﻿using System.Windows;
using System.Windows.Controls;
using KinonekoSoftware.CodariaDB.Documents.DataParts.Characters;
using KinonekoSoftware.CodariaDB.Documents.DataParts.Story;
using KinonekoSoftware.CodariaDB.Runtimes;
using KinonekoSoftware.Extensions.Reflections;
using KinonekoSoftware.Platform.Windows;
using KinonekoSoftware.Studio.Pages.Instances.Schools;

using Microsoft.Xaml.Behaviors;

namespace KinonekoSoftware.Studio.Pages.Instances
{

    [Associate(View = typeof(ClassicStyleInstanceEditorView), ViewModel = typeof(CharacterEditorViewModel))]
    [Associate(View = typeof(ClassicStyleInstanceEditorView), ViewModel = typeof(AbilityEditorViewModel))]
    public partial class ClassicStyleInstanceEditorView
    {
        private readonly Dictionary<Type, FrameworkElement> _FeatureContentMap;

        public ClassicStyleInstanceEditorView()
        {
            _FeatureContentMap = new Dictionary<Type, FrameworkElement>();
            InitializeComponent();
            
        }


        protected override void OnViewModelMessaging(object parameter)
        {
            if (parameter is null)
            {
            } 
            else if (parameter is SnapshotMessage snapshotMessage)
            {
                //
                // 这里会有截图偏移的现象，所以必须保证 ScrollViewer的偏移为0
                ScrollViewer.ScrollToTop();
                
                //
                //
                snapshotMessage.Callback ??= x => Shell.CaptureAsync(x as FrameworkElement, 120);
                
                //
                // 
                snapshotMessage.Callback(Container);
            }
            else if (parameter is string msg)
            {
                //
                //
                if (msg == MessageStringContract.GoToTopCommand)
                {
                    ScrollViewer.ScrollToTop();
                }
            }

        }

        protected override void OnUnloaded()
        {
            _FeatureContentMap.Clear();
        }

        private void OnFeatureChanged(object sender, SelectionChangedEventArgs e)
        {
        }
    }
}